﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
namespace kserv
{

    class configxml
    {

    }

    public class configSRV
    {
        public configSRV()
        {
            leXML();
        }

        private void leXML()
        {
            XmlDocument xml = new XmlDocument(); 
            string caminho = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            xml.Load( caminho + "\\dbiKcad.xml");
            XmlNodeList xnList = xml.GetElementsByTagName("config");
            foreach (XmlNode xn in xnList)
            {
                _apagaemail = xn["apagaemail"].InnerText == "1" ? true : false;
                _armxml = xn["armemail"].InnerText == "1" ? true : false;
                _dbinfeconnstring = xn["dbconnstring"].InnerText;
                _ehistorico = xn["emailhistorico"].InnerText;
                _enviarhistorico = xn["enviarhistorico"].InnerText == "1" ? true : false;
                _enviarverificacao = xn["enviarverificacao"].InnerText == "1" ? true : false;
                _everifica = xn["emailverificacao"].InnerText;
                _intervalo = Convert.ToInt32(xn["intervalo"].InnerText);
                _pop3 = xn["pop3"].InnerText;
                _senha = xn["pop3senha"].InnerText;
                _SMTP = xn["smtp"].InnerText;
                _ssenha = xn["smtpsenha"].InnerText;
                _susuario = xn["smtpuser"].InnerText;
                _temdir = xn["tempdir"].InnerText;
                _timerativo = xn["timerativo"].InnerText == "1" ? true : false;
                _usuario = xn["pop3user"].InnerText;
                _tipolog = xn["tipolog"].InnerText;
                _wsdbiurl = xn["wsdbiurl"].InnerText;
                _wsdbilogin = xn["wsdbilogin"].InnerText;
                _wsdbisenha = xn["wsdbisenha"].InnerText;
                _proxyurl = xn["proxyurl"].InnerText;
                _proxylogin = xn["proxylogin"].InnerText;
                _proxypwd = xn["proxypwd"].InnerText;
                _proxydomain = xn["proxydominio"].InnerText;
                _multipartTamanho =  Convert.ToInt32(xn["multipartTamanho"].InnerText);
                _qtdthreadsporOS = Convert.ToInt32(xn["qtdthreadsporOS"].InnerText);

            }
        }

        public void gravarSettings()
        {

            XmlDocument xml = new XmlDocument();
            string caminho = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            xml.Load(caminho + "\\dbiKcad.xml");
            XmlNodeList xnList = xml.GetElementsByTagName("config");
            foreach (XmlNode xn in xnList)
            {
                xn["emailhistorico"].InnerText = _ehistorico;
                xn["apagaemail"].InnerText = _apagaemail ? "1": "0";
                xn["armemail"].InnerText = _armxml ? "1" : "0";
                xn["dbconnstring"].InnerText = _dbinfeconnstring;
                xn["emailhistorico"].InnerText = _ehistorico;
                xn["enviarhistorico"].InnerText = _enviarhistorico ? "1": "0";
                xn["enviarverificacao"].InnerText = _enviarverificacao ? "1": "0";
                xn["emailverificacao"].InnerText = _everifica;
                xn["intervalo"].InnerText = _intervalo.ToString();
                xn["pop3"].InnerText = _pop3;
                xn["pop3senha"].InnerText = _senha;
                xn["smtp"].InnerText = _SMTP;
                xn["smtpsenha"].InnerText = _ssenha;
                xn["smtpuser"].InnerText = _susuario;
                xn["tempdir"].InnerText = _temdir;
                xn["timerativo"].InnerText = _timerativo ? "1": "0";
                xn["pop3user"].InnerText = _usuario;
                xn["wsdbiurl"].InnerText = _wsdbiurl;
                xn["wsdbilogin"].InnerText = _wsdbilogin;
                xn["wsdbisenha"].InnerText = _wsdbisenha;
                xn["multipartTamanho"].InnerText = _multipartTamanho.ToString();
                xn["qtdthreadsporOS"].InnerText = _qtdthreadsporOS.ToString();

            }
            xml.Save(caminho + "\\dbiKcad.xml");
            //Properties.app.Default.apagaEmail = _apagaemail; ;
            //Properties.app.Default.armXml = _armxml;
            //Properties.app.Default.dbinfeconnstring = _dbinfeconnstring;
            //Properties.app.Default.ehistorico = _ehistorico;
            //Properties.app.Default.enviarhistorico = _enviarhistorico;
            //Properties.app.Default.enviarverificacao = _enviarverificacao;
            //Properties.app.Default.everifica = _everifica;
            //Properties.app.Default.intervalo = _intervalo;
            //Properties.app.Default.pop3 = _pop3;
            //Properties.app.Default.senha = _senha;
            //Properties.app.Default.SMTP = _SMTP;
            //Properties.app.Default.ssenha = _ssenha;
            //Properties.app.Default.susuario = _susuario;
            //Properties.app.Default.tempdir = _temdir;
            //Properties.app.Default.timerativo = _timerativo;
            //Properties.app.Default.usuario = _usuario;

            //Properties.app.Default.Save();
            //Properties.app.Default.Reload();
        }
        private string _pop3, _usuario, _senha, _dbinfeconnstring, _temdir, _SMTP, _susuario, _ssenha, _everifica, _ehistorico, _tipolog, _wsdbiurl, _wsdbilogin, _wsdbisenha, _proxyurl, _proxylogin, _proxypwd, _proxydomain;
        private bool _armxml, _apagaemail, _enviarverificacao, _enviarhistorico, _timerativo;
        private int _intervalo, _multipartTamanho, _qtdthreadsporOS;

        public string TIPOLOG { get { return _tipolog; } set { _tipolog = value; } }
        public string POP3 { get { return _pop3; } set { _pop3 = value; } }
        public string USUARIO { get { return _usuario; } set { _usuario = value; } }
        public string SENHA { get { return _senha; } set { _senha = value; } }
        public string DBINFECONNSTRING { get { return _dbinfeconnstring; } set { _dbinfeconnstring = value; } }
        public string TEMPDIR { get { return _temdir; } set { _temdir = value; } }
        public string SMTP { get { return _SMTP; } set { _SMTP = value; } }
        public string SMTPUSUARIO { get { return _susuario; } set { _susuario = value; } }
        public string SMTPSENHA { get { return _ssenha; } set { _ssenha = value; } }
        public string EVERIFICA { get { return _everifica; } set { _everifica = value; } }
        public string EHISTORICO { get { return _ehistorico; } set { _ehistorico = value; } }
        public string WSDBIURL { get { return _wsdbiurl; } set { _wsdbiurl = value; } }
        public string WSDBILOGIN { get { return _wsdbilogin; } set { _wsdbilogin = value; } }
        public string WSDBISENHA { get { return _wsdbisenha; } set { _wsdbisenha = value; } }
        public bool ARMXML { get { return _armxml; } set { _armxml = value; } }
        public bool APAGAEMAIL { get { return _apagaemail; } set { _apagaemail = value; } }
        public bool ENVIARVERIFICACAO { get { return _enviarverificacao; } set { _enviarverificacao = value; } }
        public bool ENVIARHISTORICO { get { return _enviarhistorico; } set { _enviarhistorico = value; } }
        public bool TIMERATIVO { get { return _timerativo; } set { _timerativo = value; } }
        public int INTERVALO { get { return _intervalo; } set { _intervalo = value; } }
        public string PROXYURL { get { return _proxyurl; } }
        public string PROXYLOGIN { get { return _proxylogin; } }
        public string PROXYPWD { get { return _proxypwd ; } }
        public string PROXYDOMAIN { get { return _proxydomain; } }
        public int MULTIPARTTAMANHO { get { return _multipartTamanho; } set { _multipartTamanho = value; } }
        public int QTDTHREADSPOROS { get { return _qtdthreadsporOS; } set { _qtdthreadsporOS = value; } }
        

        //public static bool TIMERehAtivo()
        //{
        //    return Properties.app.Default.timerativo;
        //}
        //public static int QUALoINTERVALO()
        //{
        //    return Properties.app.Default.intervalo;
        //}
    }
}
